//
//  RecommendHeadView.m
//  CommonFrame
//
//  Created by Bang-guo on 15/7/20.
//  Copyright (c) 2015年 guobang. All rights reserved.
//

#import "RecommendHeadView.h"
#import <UIImageView+WebCache.h>
@implementation RecommendHeadView

-(instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        
        [self createSubViews];
        
    }
    
    return self;
}

-(void)createSubViews {
//    nameL;
//    first_dayL;
//    mileageL;
//    recommendationsL;
//    userNameL;
//    avatar_mImage;
    
    self.nameL = [[BaseLabel alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 50)];
//    self.nameL.backgroundColor = [UIColor greenColor];
    [self addSubview:self.nameL];
    self.nameL.textAlignment = NSTextAlignmentCenter;
    
    self.avatar_mImage = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH / 2 - 35, self.nameL.frame.size.height, 70, 70)];
    self.avatar_mImage.layer.masksToBounds = YES;
    self.avatar_mImage.layer.cornerRadius = 35;
    [self addSubview:self.avatar_mImage];
//    self.avatar_mImage.backgroundColor = [UIColor orangeColor];
    
    self.userNameL = [[BaseLabel alloc] initWithFrame:CGRectMake(0, self.avatar_mImage.frame.origin.y + self.avatar_mImage.frame.size.height, WIDTH, 20)];
//    self.userNameL.backgroundColor = [UIColor blueColor];
    [self addSubview:self.userNameL];
    self.userNameL.textAlignment = NSTextAlignmentCenter;
    
    self.first_dayL = [[BaseLabel alloc] initWithFrame:CGRectMake(0, self.userNameL.frame.origin.y + self.userNameL.frame.size.height, WIDTH / 3, 30)];
//    self.first_dayL.backgroundColor = [UIColor purpleColor];
    [self addSubview:self.first_dayL];
    self.first_dayL.textAlignment = NSTextAlignmentCenter;
    self.first_dayL.font = [UIFont systemFontOfSize:15.0];
    
    self.mileageL = [[BaseLabel alloc] initWithFrame:CGRectMake(WIDTH / 3, self.userNameL.frame.origin.y + self.userNameL.frame.size.height, WIDTH / 3, 30)];
//    self.mileageL.backgroundColor = [UIColor yellowColor];
    [self addSubview:self.mileageL];
    self.mileageL.textAlignment = NSTextAlignmentCenter;
    self.mileageL.font = [UIFont systemFontOfSize:15.0];
    
    
    self.recommendationsL = [[BaseLabel alloc] initWithFrame:CGRectMake(WIDTH / 3 * 2, self.userNameL.frame.origin.y + self.userNameL.frame.size.height, WIDTH / 3, 30)];
//    self.recommendationsL.backgroundColor = [UIColor greenColor];
    [self addSubview:self.recommendationsL];
    self.recommendationsL.textAlignment = NSTextAlignmentCenter;
    self.recommendationsL.font = [UIFont systemFontOfSize:15.0];
    
    self.lable = [[BaseLabel alloc] initWithFrame:CGRectMake(0, self.recommendationsL.frame.origin.y + self.recommendationsL.frame.size.height, WIDTH, 20)];
    self.lable.textAlignment = NSTextAlignmentCenter;
    self.lable.text = @"查看线路日程";

    
    BaseView *aView = [[BaseView alloc] initWithFrame:CGRectMake(0, self.lable.frame.origin.y + self.lable.frame.size.height, WIDTH, 1)];
    aView.backgroundColor = [UIColor lightGrayColor];
    [self addSubview:aView];
    

}

-(void)setRecommendValue:(RecommendDetail *)recD {
    [self addSubview:self.lable];
    self.nameL.text = recD.name;
    [self.avatar_mImage sd_setImageWithURL:[NSURL URLWithString:recD.avatar_m] placeholderImage:[UIImage imageNamed:@"icon1024.png"]];
    self.userNameL.text = recD.userName;
    if (WIDTH < 375) {
        
        NSString *str1 = [NSString stringWithFormat:@"日期:%@", recD.first_day];
        NSString *str2 = [str1 substringToIndex:10];
        self.first_dayL.text = str2;
    } else {
        
        NSString *str1 = [NSString stringWithFormat:@"日期:%@", recD.first_day];
        self.first_dayL.text = str1;
    }
    float f = [recD.mileage floatValue];
    NSString *str = [NSString stringWithFormat:@"%.f",f];
    self.mileageL.text = [NSString stringWithFormat:@"里程:%@", str];
    self.recommendationsL.text = [NSString stringWithFormat:@"喜欢:%@", recD.recommendations];
    
    
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
